package com.shanshan.manage.web.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.shanshan.manage.common.annotation.Log;
import com.shanshan.manage.common.core.controller.BaseController;
import com.shanshan.manage.common.core.domain.AjaxResult;
import com.shanshan.manage.common.enums.BusinessType;
import com.shanshan.manage.web.domain.AInventory;
import com.shanshan.manage.web.service.IAInventoryService;
import com.shanshan.manage.common.utils.poi.ExcelUtil;
import com.shanshan.manage.common.core.page.TableDataInfo;

/**
 * 库存管理Controller
 *
 * @author zhaoshuheng
 * @date 2023-09-04
 */
@RestController
@RequestMapping("/aInventory/aInventory")
public class AInventoryController extends BaseController {
    @Autowired
    private IAInventoryService aInventoryService;

    /**
     * 查询库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('aInventory:aInventory:list')")
    @GetMapping("/list")
    public TableDataInfo list(AInventory aInventory) {
        startPage();
        List<AInventory> list = aInventoryService.selectAInventoryList(aInventory);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('aInventory:aInventory:list')")
    @GetMapping("/listAInventoryNoPage")
    public TableDataInfo listAInventoryNoPage(AInventory aInventory) {
        List<AInventory> list = aInventoryService.selectAInventoryList(aInventory);
        return getDataTable(list);
    }

    /**
     * 导出库存管理列表
     */
    @PreAuthorize("@ss.hasPermi('aInventory:aInventory:export')")
    @Log(title = "库存管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, AInventory aInventory) {
        List<AInventory> list = aInventoryService.selectAInventoryList(aInventory);
        ExcelUtil<AInventory> util = new ExcelUtil<AInventory>(AInventory.class);
        util.exportExcel(response, list, "库存管理数据");
    }

    /**
     * 获取库存管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('aInventory:aInventory:query')")
    @GetMapping(value = "/{inventoryId}")
    public AjaxResult getInfo(@PathVariable("inventoryId") Long inventoryId) {
        return success(aInventoryService.selectAInventoryByInventoryId(inventoryId));
    }

    /**
     * 新增库存管理
     */
    @PreAuthorize("@ss.hasPermi('aInventory:aInventory:add')")
    @Log(title = "库存管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AInventory aInventory) {
        return toAjax(aInventoryService.insertAInventory(aInventory));
    }

    /**
     * 修改库存管理
     */
    @PreAuthorize("@ss.hasPermi('aInventory:aInventory:edit')")
    @Log(title = "库存管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AInventory aInventory) {
        return toAjax(aInventoryService.updateAInventory(aInventory));
    }

    /**
     * 删除库存管理
     */
    @PreAuthorize("@ss.hasPermi('aInventory:aInventory:remove')")
    @Log(title = "库存管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{inventoryIds}")
    public AjaxResult remove(@PathVariable Long[] inventoryIds) {
        return toAjax(aInventoryService.deleteAInventoryByInventoryIds(inventoryIds));
    }
}
